#include "../include/twentySix_26.h"


Revolve::Revolve()
{

}

Revolve::Revolve(char *str)
{
    if (NULL != str)
    {
        m_pStr = new char[strlen(str) + 1];
        strcpy(m_pStr, str);
    }
}


Revolve::~Revolve()
{
    if (NULL != m_pStr)
    {
        delete[]  m_pStr;
    }
}


Revolve::Revolve(const Revolve &th)
{
    if (NULL != th.m_pStr)
    {
        m_pStr = new char[strlen(th.m_pStr) + 1];
        strcpy(m_pStr, th.m_pStr);
    }
}


Revolve& Revolve::operator= (const Revolve &ff)
{
    if (this == &ff)
        return *this;

    char *p = m_pStr;
    m_pStr = new char[strlen(ff.m_pStr) + 1];
    delete p;
    return *this;

}

void Revolve::swap(char &a, char &b)
{
    if (a != b)
    {
        char tmp = a;
        a = b;
        b = tmp;
    }
}

void Revolve::doRevolve(int n)
{
    if (n <= 0)
    {
        cout << "the parameter is wrong , please check it!" << endl;
        return;
    }

    int i = 0;
    int str_count = strlen(m_pStr);

    while (i + n < str_count)
    {
        swap(m_pStr[i], m_pStr[i + n]);
        i++;
    }
}

void Revolve::Print()
{
    cout << m_pStr << endl;
}


void TestFor26()
{
    const unsigned int num = 100;
    char str[num];
    memset(str, 0, num);

    cout << "Please input your string that length is less than " << num
    << " !"<<endl;
    gets(str);

    Revolve revolvo(str);
    revolvo.doRevolve(2);
    revolvo.Print();
}



